<script setup lang="ts">
import { RouterView } from 'vue-router'
import Head from './components/head.vue'
import Foot from './components/foot.vue'
import Bread from './components/Breadcrumbs.vue'
import { ref, watchEffect } from 'vue'
import { getWebInfo } from './api/web'
import { useWebInfoStore } from './stores/webInfo'
const webInfoStore = useWebInfoStore()
let header_show = ref(true)
let footer_show = ref(true)
const footer = (bool: boolean) => {
  footer_show.value = bool
}
import { useRoute } from 'vue-router'
let route = useRoute()
const head_child = ref()
const header = (bool: boolean) => {
  header_show.value = bool
  head_child.value.updateNav(route.query.id)
}
getWebInfo().then((res: any) => {
  webInfoStore.setWebInfo(res)
  document.title = res.site_name
})

let bread_show = ref(true)
const bread = (value: boolean) => {
  bread_show.value = value
}
watchEffect(() => {
  if (route.path == '/' || route.path == '/login') {
    bread_show.value = false
  } else {
    bread_show.value = true
  }
  if (route.path !== '/login') {
    header_show.value = true
  }
})
</script>

<template>
  <div class="fixHeader" v-if="header_show">
    <Head ref="head_child" />
  </div>

  <div v-if="bread_show" class="bread">
    <Bread />
  </div>
  <RouterView
    :style="{ 'margin-top': header_show && !bread_show ? '170px' : '0px' }"
    v-on:header="header"
    v-on:footer="footer"
    v-on:bread="bread"
  />
  <div v-if="footer_show">
    <Foot />
  </div>
</template>

<style lang="scss" scoped>
.bread {
  margin-top: 170px;
}
@import '@/assets/style/theme.scss';
.fixHeader {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 999;
  transition: all 0.5s;
}

.logo {
  display: block;
  margin: 0 auto 2rem;
}

nav {
  width: 100%;
  font-size: 12px;
  text-align: center;
  margin-top: 2rem;
}

nav a.router-link-exact-active {
  color: var(--color-text);
}

nav a.router-link-exact-active:hover {
  background-color: transparent;
}

nav a {
  display: inline-block;
  padding: 0 1rem;
  border-left: 1px solid var(--color-border);
}

nav a:first-of-type {
  border: 0;
}

@media (min-width: 1024px) {
  header {
    display: flex;
    place-items: center;
    padding-right: calc(var(--section-gap) / 2);
  }

  .logo {
    margin: 0 2rem 0 0;
  }

  header .wrapper {
    display: flex;
    place-items: flex-start;
    flex-wrap: wrap;
  }

  nav {
    text-align: left;
    margin-left: -1rem;
    font-size: 1rem;

    padding: 1rem 0;
    margin-top: 1rem;
  }
}
</style>
